#include <stdio.h>
#include <stdlib.h>
#include "functions.h"
#include "gui.h"

void desc(void) {
	fprintf(stdout, "Emulator maszyny Turinga obliczajacy roznice wlasciwa m i n\n\n"
			"m - n = { m - n dla m >= n\n"
			"        { 0     dla m < n\n\n"
			"Maszyna jest postaci\n"
		       	"M = ( {q0, q1, .., q6}, {0,1}, {0,1,B}, δ, q0, B, 0 )\n\n");
}
void states_desc(void) {
	fprintf(stdout, " δ	    0		    1		    B\n"
			"q0	(q1,B,P)	(q5,B,P)	    -\n"
			"q1	(q1,0,P) 	(q2,1,P)	    -\n"
			"q2	(q3,1,L)	(q2,1,P) 	(q4,B,L)\n"
			"q3	(q3,0,L) 	(q3,1,L)	(q0,B,P)\n"
			"q4	(q4,0,L) 	(q4,B,L)	(q6,0,P)\n"
			"q5	(q5,B,P) 	(q5,B,P)	(q6,B,P)\n"
			"q6	    -		    -		    -\n");
}
void proper_using(void) {
	fprintf(stderr, "\n\nUzycie: ./mt [m] [n] [-o plik]\n"
			"argumenty sa opcjonalne, program mozna uruchomic bez nich\n\n"
			"jezeli jednak chcesz aby program zapisal swoje wyniki do pliku,\n"
			"uzyj podanego schematu\n");

	exit(EXIT_SUCCESS);
}

void fprint_tape(int *tape, int tape_lgt, FILE *out) {
	int i;
	for(i = 0; i < tape_lgt; i++) {
			if(tape[i] == 8)
				;
			else
	
				fprintf(out, "%d", tape[i]);
	}
}


void inst_desc(int *tape, int tape_lgt, int crpos, int state, FILE *out) {
	int i;
	int end = last_non_empty(tape, tape_lgt);
	for(i = 0; i < crpos ; i++) {
			if(tape[i] == 8)
				fprintf(out, "B");
			else
				fprintf(out, "%d", tape[i]);
	}

	fprintf(out, "(q%d)", state);
	for(;i <= end; i++) {
		if(tape[i] == 8)
			fprintf(out, "B");
		else
			fprintf(out, "%d", tape[i]);
	}
	fprintf(out, "|-");
}
